﻿/*
   Copyright 2013 Dmitry Bratus

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Flower.Services.Data;
using Jurassic.Library;

namespace Flower.Directory.Scripting.DirectoryEntries
{
    public class DirectoryEntryInfoObject : DirectoryEntryObject
    {
        public override DirectoryEntry Entry
        {
            get
            {
                ((DirectoryEntryInfo)_entry).Type = (DirectoryEntryTypes)this.GetInt("type");
                return base.Entry;
            }
        }

        public DirectoryEntryInfoObject(ObjectInstance prototype, DirectoryEntryInfo entry)
            : base(prototype, entry)
        {
            _entry = entry;
            
            if (entry != null)
            {
                this.Set("type", (int)entry.Type);
            }
        }

        public DirectoryEntryInfoObject(ObjectInstance prototype)
            : this(prototype, null)
        {
            _entry = new DirectoryEntryInfo();
        }

        [JSFunction(Name = "getType")]
        public override int GetDirectoryEntryType()
        {
            return this.GetInt("type");
        }
    }
}
